package org.ccay.security.entity;

import java.io.Serializable;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.ccay.security.authc.ProgramAuthorizationInfo;

/**
 * Program相当于定义了角色的范围。在不同的Program下，用户可能拥有不同的角色。
 * Program可以挂接任何具体的范围，例如部门、区域等
 * 已定义按照功能划分的Program 
 * @author chaowangbang
 * @since 2017年2月5日
 */
public class Program implements Serializable{


	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	
	/**
	 * 默认的全部范围
	 */
	public static final Program PROGRAM_All;
	
	
	/**
	 * 数据范围中，标识当前值的符号
	 */
	public static final String CURRENT_VALUE = "CURRENT_VALUE";

	//功能Program
	static{
		PROGRAM_All = new Program(ProgramAuthorizationInfo.PROGRAM_ALL_ID,ProgramAuthorizationInfo.PROGRAM_ALL_NAME);
	}
	
	/**
	 * ID
	 */
	private Long programId;
	/**
	 * Name
	 */
	private String programName;
	
	/**
	 * 维度及维度值
	 */
	private Map<String,LinkedHashSet<Serializable>> dimensions = new HashMap<String,LinkedHashSet<Serializable>>();
	
	/**
	 * 默认无参构造
	 */
	public Program() {}
	

	public Program(Long programId,String programName) {
		this.programId = programId;
		this.programName = programName;
	}
	

	public Map<String, LinkedHashSet<Serializable>> getDimensions() {
		return dimensions;
	}

	public void setDimensions(Map<String, LinkedHashSet<Serializable>> dimensions) {
		this.dimensions = dimensions;
	}
	
	public Long getProgramId() {
		return programId;
	}

	public void setProgramId(Long programId) {
		this.programId = programId;
	}

	public String getProgramName() {
		return programName;
	}

	public void setProgramName(String programName) {
		this.programName = programName;
	}


	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((programId == null) ? 0 : programId.hashCode());
		result = prime * result
				+ ((programName == null) ? 0 : programName.hashCode());
		return result;
	}


	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Program other = (Program) obj;
		if (programId == null) {
			if (other.programId != null)
				return false;
		} else if (!programId.equals(other.programId))
			return false;
		if (programName == null) {
			if (other.programName != null)
				return false;
		} else if (!programName.equals(other.programName))
			return false;
		return true;
	}
	
	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append("Program [programId=");
		builder.append(programId);
		builder.append(", programName=");
		builder.append(programName);
		builder.append(", dimensions=");
		builder.append(dimensions);
		builder.append("]");
		return builder.toString();
	}

	
}
